home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48hor1
/
gse1.doc
< prev
next >
Wrap
Text File
|
1995-03-31
|
8KB
|
181 lines
GSE1 Directory - Goal Seeking Engine version 1 - 4/91 [**SHAREWARE**]
Copyright 1991, Jeff Duncombe
[Included on Goodies Disk #3 with the author's permission. -jkh-]
What if one program could find out the fewest number of floppies to
copy your enormous number of files onto? Or maybe balance your checkbook?
What about making perfectly timed audio cassettes?
GSE is a utility for finding what combination of a group of numbers
will total to a goal number (within a certain accuracy). There are many
applications that are tailor-made to this type of an engine; three are provided
for example.
The basic stack setup is as follows:
3:[Vector of numbers]
2:Goal =====>
1:Accuracy 1:[Answer Vector]
For example, assume there are a group of numbers: 6, 4, 3, 2. What
combination of these numbers will equal 7?
Load the stack as follows:
3: [6 4 3 2] yields
2: 7 =====>
1: 0 1: [0 4 3 0]
This means that of the four item list, the combination of 4 and 3 will
yield the goal of 7.
Not very exciting, you say? Here's a better one: you have a directory
of 8 files (100K, 230K, 310K, 130K, 170K, 50K, 260K, 190K). Assume that you
want to put these onto the fewest number of 360K floppies. If you total them
(put the vector in level 1 and CNRM), you will find they total 1440K, or 4 x
360K disks. But if you use the standard COPY command, they will end up taking
5 diskettes, as follows:
100K 230K | 310K | 130K 170K | 50K 260K | 190K
Disk 1 | Disk 2 | Disk 3 | Disk 4 | Disk 5
This is a problem for GSE; it will find you a way using only 4 disks!
(Hint: It is a good idea to have the original vector in 3 and 4, so a copy will
still be available).
Load the stack:
4:[100 230 310 130 170 50 260 190]
3:[100 230 310 130 170 50 260 190]
2:360 =====> 2:[100 230 310 130 ...]
1:0 1:[100 0 0 0 0 0 260 0]
The first answer: 100K and 260K should fill the first disk. Notice
that flag 1 is set on the screen, which means that the goal of 360 was found
within the desired accuracy of 0. If flag 1 was clear, the best answer would
be displayed, but it wouldn't be within the limits.
Now press [-] (the minus key) and [ENTER]. This will take out the
known solution from the list and leave you with the next argument (properly
DUPlicated). Fill 1 & 2 with the desired info and try it again:
4:[0 230 310 130 170 50 0 190]
3:[0 230 310 130 170 50 0 190]
2:360 =====> 2:[0 230 310 130 17...]
1:0 1:[0 230 0 130 0 0 0 0]
The next answer is 230K and 130K. After a [-], [ENTER], 360 and 0, you
continue:
4:[0 0 310 0 170 50 0 190]
3:[0 0 310 0 170 50 0 190]
2:360 =====> 2:[0 0 310 0 170 50...]
1:0 1:[0 0 310 0 0 50 0 0]
The third disk shall hold the 310K file and the 50K file. [-],
[ENTER], 360, 0:
4:[0 0 0 0 170 0 0 190]
3:[0 0 0 0 170 0 0 190]
2:360 =====> 2:[0 0 0 0 170 0 0 ...]
1:0 1:[0 0 0 0 170 0 0 190]
The fourth and final disk should therefore hold 170K and 190K.
The possibilities are endless. As another example, say that you needed
to balance your checkbook. Just type in a vector of all the checks that you
wrote, then set your final balance as the goal (don't forget any little bank
fees). Follow the example below:
You've written checks for $32.56, $27.90, $130.21, and $46.35. Your
total for checks written is $106.81. Solve:
3:[32.56 27.90 130.21 46.35]
2:106.81 =====>
1:0 1:[32.56 27.9 0 46.35]
The check for 130.21 must still be uncashed.
As the last example, I will use the problem that inspired me to write
this program in the first place. I want to tape some songs from CD to audio
cassette. The cassette is 45 minutes on each side, for a total of 90 minutes.
There should be a way to place the songs selectively on each side so as to fit
every song in its entirety. This is more difficult than it sounds, if you
don't have a computer, because there are generally 20+ songs to deal with.
Anyway, here are the song lengths (in seconds):
[540 482 669 841 334 592 604 612 381 344]
The goal is 2700 seconds (45 minutes). The accuracy will be 0.
4:[540 482 669 841 ...]
3:[540 482 669 841 ...]
2:2700 =====> 2:[540 482 669 841 ...]
1:0 1:[540 0 0 841 334 ...]
The first side of the tape must contain the songs the are lengths 540,
841, 334, 604, and 381 for a total of exactly 2700 seconds. A simple [-] and
you get what songs go on the second side (482, 669, 592, 612, and 344).
That's it for the examples. Here are just a few random specs to help
you on your way:
* This engine uses error checking, so don't worry about your arguments causing
a system crash.
* Flags 1, 2, & 3 are used by this program. They are all cleared at the
beginning and modified during the course of the execution. Their descriptions
are as follows:
Set Clear
Flag 1: The answer is within The answer is the closest to
the desired accuracy. the accuracy as possible, but
NOT within it.
Flag 2: The argument is a two- The program runs normally.
dimensional array.
The arguments are left
alone.
Flag 3: (This flag is always clear at the end of the engine)
* If a complex vector is given as an argument, it will be converted to the real
part only. Example: [(2,3) (4,5) (6,4) (3,2)] would be considered to be [2 4 6
3].
Note: The [-] still works with a complex and a real-only vector, as shown:
2:[(2,3) (4,5) (6,4)] [-]
1:[0 4 0] =====> 1:[(2,3) (0,5) (6,4)]
* Although GSE appears to be the only program in the GSE1 directory, there are
three "hidden" files called GSEV, GSER, and MMUL. These programs are
subroutines of GSE, and should not be used alone, for they can cause a Memory
Clear if not used correctly. GSE uses them correctly, so they are hidden from
the VAR menu. But this means that the GSE program cannot be removed from the
GSE1 directory and used alone. If you wish to call GSE from your own software,
you may make the GSE1 directory into a library. [See USRLIB on EduCALC Goodies
Disk #1. -jkh-]
Now for the disclaimer:
This program contains undocumented features of the HP 48SX and consequently I
bear no responsibility for any damage it may cause. (I haven't ever had a
problem, though).
If you decide that this engine is worth while to use in your personal or
commercial applications, I would appreciate some compensation for this. This
first version contains only the "bare-bones" of what I have envisioned this
application to be. Future releases shall include batch goal-seeking (having
multiple goals with the same vector and minimizing the overall difference),
speed enhancements (in theory there should be a big future for this one), and
some bonus features. Remember, the only way to be alerted to these changes is
to register for that privilege. Send your donations to:
Jeff Duncombe
PO Box 20098
Fountain Valley, CA 92708
(Suggested amounts are $10 for personal use, commercial royalties may
vary. Contact me for details.)
Happy Goal Seeking!